using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WLYT.Application.Interfaces;
using WLYT.Domain.Model;
using WLYT.Repository;

namespace WLYT.Application.Services
{	
    public class OrderItemDetailService : BaseService<OrderItemDetail>, IOrderItemDetailService
    {
        public ISqlSugarRepository<OrderItemDetail> OrderItemDetailRepository;
        public OrderItemDetailService(ISqlSugarRepository<OrderItemDetail> orderItemDetailRepository) : base(orderItemDetailRepository)
        {
            OrderItemDetailRepository = orderItemDetailRepository;
        }

        public async Task<Tuple<IList<OrderItemDetail>, int>> GetModelsByPageAsync(int type, string docType, int? status, string docNum, string labelId, int pageSize, int pageIndex)
        {
            Expressionable<OrderItemDetail> exp = Expressionable.Create<OrderItemDetail>();
            if(type == 0)
            {
                exp.And(p => p.DocType == "R-001" || p.DocType == "R-002" || p.DocType == "S-002");
            }
            else
            {
                exp.And(p => p.DocType == "C-001" || p.DocType == "C-002" || p.DocType == "S-001" || p.DocType == "S-003");
            }
            exp.AndIF(docType != null, p => p.DocType == docType);
            exp.AndIF(status != null, p => p.Status == status);
            exp.AndIF(!string.IsNullOrEmpty(docNum), p => p.DocNum.Contains(docNum));
            exp.AndIF(!string.IsNullOrEmpty(labelId), p => p.LabelId.Contains(labelId));
            return await GetPageListAsync(exp, pageSize, pageIndex, p => p.Id);
        }
    }
}